<%-- 
    Document   : post-manage_action
    Created on : Feb 23, 2012, 4:11:30 PM
    Author     : lab
--%>


<%@page import="util.PagingUtil"%>
<%@page import="util.SharingUtil"%>
<%@page import="dto.Post"%>
<%@page import="java.util.ArrayList"%>
<%@page import="dao.PostDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    PostDAO daoPost = new PostDAO();
    boolean useSearch = false;
    String searchContent = null;
    String st = request.getParameter("selected-item-id");
    if (st != null) {
        if (!st.equals("")) {
            daoPost.delete(Integer.parseInt(st));
        }
    }
    ArrayList<Post> list = new ArrayList<Post>();
    int currentPage = PagingUtil.getPageNumber(request.getParameter("page"));
    int total = 0;
    String pagingNav = "";
    if (request.getParameter("search") != null) {
        if (!request.getParameter("search").equals("")) {
            searchContent = request.getParameter("search");
            list = daoPost.getPosts(currentPage, PagingUtil.CONST_PAGE_SIZE);
            request.setAttribute("search", searchContent);
            useSearch = true;
        } else {
            list = daoPost.getPosts(currentPage, PagingUtil.CONST_PAGE_SIZE);
        }
    } else {
        list = daoPost.getPosts(currentPage, PagingUtil.CONST_PAGE_SIZE);
    }
    total = daoPost.getTotalRecords();
    //this value is use for paging
    String requestString = "?pcontent=mmanage-post&page=";
    if (useSearch) {
        requestString += "&search=" + searchContent;
    }
    pagingNav = PagingUtil.getPageNavigator(total, PagingUtil.CONST_PAGE_SIZE, currentPage, requestString);
    request.setAttribute("list", list);
    request.setAttribute("pagingNav", pagingNav);
%>